package com.atmaowei.controller;

import com.atmaowei.common.Result;
import com.atmaowei.controller.request.TeacherPageRequest;
import com.atmaowei.entity.Course;
import com.atmaowei.entity.Department;
import com.atmaowei.entity.Teacher;
import com.atmaowei.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;


    @PostMapping("/save")
    public Result save(@RequestBody Teacher teacher) {
        teacherService.save(teacher);
        return Result.success();
    }

    @DeleteMapping("/delete/{tno}")
    public Result delete(@PathVariable String tno) {
        teacherService.delete(tno);
        return Result.success();
    }

    @GetMapping("/getCnoByCname/{cname}")
    public Result getCnoByCname(@PathVariable String cname) {
        return Result.success(teacherService.getCnoByCname(cname));
    }

    @PutMapping("/update")
    public Result update(@RequestBody Teacher teacher) {
        teacherService.update(teacher);
        return Result.success();
    }

    @GetMapping("/{tno}")
    public Result getByTno(@PathVariable String tno) {
        Teacher teacher = teacherService.getByTno(tno);
        return Result.success(teacher);
    }

    @GetMapping("/getAllCourse")
    public Result getAllCourse() {
        List<Course> courses = teacherService.getAllCourse();
        return Result.success(courses);
    }

    @GetMapping("/page")
    public Result page(TeacherPageRequest teacherPageRequest) {
        return Result.success(teacherService.page(teacherPageRequest));
    }

    @PostMapping("/deleteSelected")
    public Result deleteSelected(@RequestBody List<Teacher> teachers) {
        teacherService.deleteSelected(teachers);
        return Result.success();
    }

    @GetMapping("/statusChange/{tno}")
    public Result statusChange(@PathVariable String tno) {
        teacherService.statusChange(tno);
        return Result.success();
    }
}
